size <- 12. Later this will be
the number of rows of the matrix.x <- rnorm( size ).x1 by adding (on average 10
times smaller) noise to x:
x1 <- x + rnorm( size )/10.x and x1 should be
close to 1.0: check this with function cor.x2 and x3 by
adding (other) noise to x.size <- 12
x <- rnorm( size )
x1 <- x + rnorm( size )/10
cor( x, x1 )
[1] 0.9786104
x2 <- x + rnorm( size )/10
x3 <- x + rnorm( size )/10
x1, x2 and x3
column-wise into a matrix using
m <- cbind( x1, x2, x3 ).m.m.heatmap( m, Colv = NA, Rowv = NA, scale = "none" ).m <- cbind( x1, x2, x3 )
class( m )
[1] "matrix" "array"
head( m )
x1 x2 x3
[1,] -0.52758640 -0.693870958 -0.51319188
[2,] 0.81236496 0.952721202 0.77304519
[3,] 0.62907167 0.773583243 0.54577867
[4,] 0.10056029 -0.009765011 -0.01051464
[5,] -0.27264578 -0.339462223 -0.25689877
[6,] -0.02789576 0.079056623 0.09585140
heatmap( m, Colv = NA, Rowv = NA, scale = "none" ) # high is dark red, low is yellow
# x1, x2, x3 follow similar color pattern, they should be correlated
y1…y4 (but not correlated with
x), of the same length size.m from columns
x1…x3,y1…y4 in some
random order.y <- rnorm( size )
y1 <- y + rnorm( size )/10
y2 <- y + rnorm( size )/10
y3 <- y + rnorm( size )/10
y4 <- y + rnorm( size )/10
m <- cbind( y4, y3, x2, y1, x1, x3, y2 )
heatmap( m, Colv = NA, Rowv = NA, scale = "none" ) # high is dark red, low is yellow
cc <- cor( m ) to build the matrix of correlation
coefficients between columns of m.round( cc, 3 ) to show this matrix with 3 digits
precision.cc <- cor( m )
round( cc, 3 ) #
y4 y3 x2 y1 x1 x3 y2
y4 1.000 0.998 -0.368 0.987 -0.404 -0.263 0.998
y3 0.998 1.000 -0.354 0.987 -0.398 -0.257 0.995
x2 -0.368 -0.354 1.000 -0.292 0.972 0.963 -0.373
y1 0.987 0.987 -0.292 1.000 -0.314 -0.176 0.990
x1 -0.404 -0.398 0.972 -0.314 1.000 0.948 -0.403
x3 -0.263 -0.257 0.963 -0.176 0.948 1.000 -0.259
y2 0.998 0.995 -0.373 0.990 -0.403 -0.259 1.000
heatmap( cc, symm = TRUE, scale = "none" )
# E.g. value for (row: x1, col: y1) is the corerlation of vectors x1, y1.
# Values of 1.0 are on the diagonal: e.g. x1 is perfectly correlated with x1.
# Correlations between x, x vectors are close to 1.0.
# Correlations between y, y vectors are close to 1.0.
# Correlations between x, y vectors are close to 0.0.
Copyright © 2023 Biomedical Data Sciences (BDS) | LUMC